package rgs.sphere.jdbc.algorithm;

import org.apache.shardingsphere.api.sharding.hint.HintShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.hint.HintShardingValue;

import java.util.Arrays;
import java.util.Collection;

/**
 * @program: rgs-study0project
 * @description:
 * @author: Mr.Ren
 * @create: 2023-11-12 22:42
 **/
public class MyHintTableAlgorithm implements HintShardingAlgorithm<Integer> {

    @Override
    public Collection<String> doSharding(Collection<String> collection, HintShardingValue<Integer> hintShardingValue) {
        //product_2
        String logicTableName = hintShardingValue.getLogicTableName();
        String realTableName = logicTableName + "_" + hintShardingValue.getValues().toArray()[0];
        if (collection.contains(realTableName)){
            return Arrays.asList(realTableName);
        }
        throw new RuntimeException(realTableName+" table name is not exist");
    }
}
